<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{/layout}">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">

    <title>发表评论</title>


    <div th:replace="commons/css/css_personal::personal_css"></div>
    <div th:replace="commons/css/css_header_footer :: public_css1"></div>
    <div th:replace="commons/js/js_personal::personal_js"></div>
    <div th:replace="commons/js/js_header_footer :: public_js1"></div>
    <script th:src="@{/personal/AmazeUI-2.4.2/assets/js/jquery.raty.js}" type="text/javascript"></script>
    <link th:href="@{/personal/css/appstyle.css}" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/jquery.bootstrapvalidator/0.5.3/css/bootstrapValidator.min.css">
    <script src="https://cdn.bootcss.com/jquery.bootstrapvalidator/0.5.3/js/bootstrapValidator.min.js"></script>
</head>

<body>
<!--头 -->
<div th:replace="commons/header::public_header"></div>

<!-- Preloader -->
<div id="preloader" class="preloader">
    <div class="loader-cube">
        <div class="loader-cube__item1 loader-cube__item"></div>
        <div class="loader-cube__item2 loader-cube__item"></div>
        <div class="loader-cube__item4 loader-cube__item"></div>
        <div class="loader-cube__item3 loader-cube__item"></div>
    </div>
</div>
<!-- End Preloader -->

<b class="line"></b>
<div class="center">
    <div class="col-main">
        <div class="main-wrap">

            <div class="user-comment">
                <!--标题 -->
                <div class="am-cf am-padding">
                    <div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">发表评论</strong> / <small>Make&nbsp;Comments</small></div>
                </div>
                <hr/>
                <input type="hidden" id="orderid" th:value="${orderid}">
                <div class="comment-main">
                    <div class="comment-list" name="parent" th:each="goods : ${goodList}">
                        <div name="child">
                        <input type="hidden" name="goodsid" th:value="${goods.goodsid}">
                        <div class="item-pic">
                            <a href="#" class="J_MakePoint">
                                <img th:src="@{/pictures/}+${goods.path}" class="itempic">
                            </a>
                        </div>

                        <div class="item-title">

                            <div class="item-name">
                                <a href="#">
                                    <p class="item-basic-info"><span th:text="${goods.goodsname}"></span></p>
                                </a>
                            </div>
                            <div class="item-info">
                                <div class="info-little">
                                    <span th:text="'商品分类：'+${goods.cateName}"></span>
                                    <p class="info-little" th:text="${goods.detailcate}"></p>
                                </div>
                                <div class="item-price">
                                    价格：<strong th:text="${goods.price}"></strong>
                                </div>
                            </div>
                        </div>
                        <div class="clear"></div>
                        <div class="item-comment">
                            <!--<textarea placeholder="请写下对宝贝的感受吧，对他人帮助很大哦！"></textarea>-->

                            <div class="info-btn">
                                <span>请写下对宝贝的感受吧，对他人帮助很大哦！</span>
                            <div class="am-btn am-btn-danger" name="addComment">发表评论</div>
                            </div>
                        </div>
                    </div>
                </div>
                </div>
            </div>

        </div>
        <!--底部-->
        <div th:replace="commons/personal_footer::personal_footer"></div>
    </div>

    <div th:replace="commons/personal_footer::personal_menu"></div>
</div>
    <div th:replace="/commons/modal::addComment"></div>
</body>
<script type="text/javascript">

$(document).ready(function () {
    $(document).ready(function () {
        changeStatus();
    })

    function changeStatus() {
        $("#li_comments").addClass("active");
    }
});


    var goodsId={};
    var orderid=$('#orderid').val();
    var lock;

    $("[name='addComment']").click(function () {
        goodsId = $(this).parents("[name='parent']").find("[name='goodsid']").val();
        var index =$(this).parents("[name='child']");
        lock = index;
        $("#evaluate").modal({
            backdrop:'static'
        });
        $("#star").raty({path: '/pictures/img'});
    });



    $("#saveEvaluate").click(function () {
        //表单验证
        $('#updatePsw-form').bootstrapValidator({
            message:'信息输入错误',
            feedbackIcons:{
                valid:'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields:{
                content:{
                    validators:{
                        notEmpty:{
                            message:'评价不能为空'
                        }
                    }

                }
            }

        });
        //校验数据
        $('#updatePsw-form').data('bootstrapValidator').validate();
        if(!$('#updatePsw-form').data('bootstrapValidator').isValid()){
            return;
        }

        var score = $("[name='score']").val();
        var content = $("#desc").val();
        var comment={};
        comment.commentid={};
        comment.userid={};
        comment.goodsid=goodsId;
        comment.point = score;
        comment.content = content;

        $.ajax({
            type:"POST",
            url:"/comments/addComment",
            data:comment,
            dataType:"json",
            success:function (result) {
                $("#evaluate").modal('hide');
                swal({
                    title:result.msg,
                    type:'success'
                });
                document.getElementById("updatePsw-form").reset();
                lock.hide();
                $.ajax({
                    type:"POST",
                    url:"/comments/commentFin",
                    data:{orderid: orderid},
                });
                $("#updatePsw-form").data('bootstrapValidator').destroy();
            },
            error:function () {
                swal({
                    title:"评论失败",
                    type:'error'
                });
            }
        });
    });



</script>
</html>